import axios from "axios";

const instance = axios.create({
  baseURL: "http://localhost:8080", // 替换为实际后端域名
  timeout: 5000,
});

// 请求拦截器：自动添加 Token 到请求头
instance.interceptors.request.use(
  (config) => {
    const token = localStorage.getItem("token");
    if (token) {
      config.headers.Authorization = `Bearer ${token}`; // 按后端要求格式携带
    }
    return config;
  },
  (error) => Promise.reject(error)
);

export default instance;
